package edu.ccut.saturn.studio.logic.model;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

import org.eclipse.gef.EditPart;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public abstract class BasicShape implements Serializable {

	private static final long serialVersionUID = 1;

	private transient PropertyChangeSupport pcsDelegate = new PropertyChangeSupport(
			this);

	private BasicShape parent;

	private EditPart editPart;

	public EditPart getEditPart() {
		return editPart;
	}

	public void setEditPart(EditPart editPart) {
		this.editPart = editPart;
	}

	public BasicShape getParent() {
		return parent;
	}

	public void setParent(BasicShape parent) {
		this.parent = parent;
	}

	public synchronized void addPropertyChangeListener(
			PropertyChangeListener propertyChangeListener) {
		if (propertyChangeListener == null) {
			throw new IllegalArgumentException();
		}
		pcsDelegate.addPropertyChangeListener(propertyChangeListener);
	}

	public synchronized void removePropertyChangeListener(
			
			PropertyChangeListener l) {
		if (l != null) {
			pcsDelegate.removePropertyChangeListener(l);
		}
	}

	protected void firePropertyChange(String property, Object oldValue,
			Object newValue) {
		if (pcsDelegate.hasListeners(property)) {
			pcsDelegate.firePropertyChange(property, oldValue, newValue);
		}
	}
	
	private void readObject(ObjectInputStream in) throws IOException,            
	ClassNotFoundException {
		in.defaultReadObject();
		pcsDelegate = new PropertyChangeSupport(this);
}
	
	public Shell getShell() {
		return Display.getDefault().getShells()[0];
	}
}
